package stableproject;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;

import japa.parser.ast.body.MethodDeclaration;
import japa.parser.ast.body.ModifierSet;
import japa.parser.ast.body.Parameter;
import japa.parser.ast.visitor.VoidVisitorAdapter;

/**
 * Simple visitor implementation for visiting MethodDeclaration nodes.
 */
public class MethodVisitor extends VoidVisitorAdapter {

	public List<String> publicMethods;
	public HashMap<String, List> methodList;

	public MethodVisitor() {
		methodList = new HashMap();
		publicMethods = new ArrayList<String>();
	}

	@Override
	public void visit(MethodDeclaration n, Object arg) {
		ParameterVisitor pm = new ParameterVisitor();

		// keep track of public methods
		if (ModifierSet.isPublic(n.getModifiers()))
			publicMethods.add(n.getName());

		pm.visit(n, null);
		methodList.put(n.getName(), pm.paramList);
		pm.paramList = null;

	}

	/* Clear the fields */
	public void cleanse() {
		publicMethods.clear();
		methodList.clear();
	}

}
